//
//  ServiceVC.m
//  reSearchDemo
//
//  Created by 科技 on 15/7/29.
//  Copyright (c) 2015年 Kiwaro. All rights reserved.
//

#import "ServiceVC.h"
#import "MenuView.h"
@interface ServiceVC ()<UITableViewDelegate,UITableViewDataSource>
{
    UITableView *_tableView;
    NSMutableArray *_dataSource;
}
@property(nonatomic,strong)MenuView *menuView;
@end

@implementation ServiceVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self setRightBarButtonImage:LOADIMAGE(@"btn_more") highlightedImage:nil selector:@selector(menu)];
    
    UIView *actionbar = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.width, 44)];
    self.navigationItem.titleView = actionbar;
    UILabel *lab = [[UILabel alloc] initWithFrame:CGRectMake(8, 0, 100, 40)];
    lab.text = @"申请服务商";
    lab.font = [UIFont systemFontOfSize:20];
    lab.textColor = [UIColor whiteColor];
    [actionbar addSubview:lab];
    
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0,CGRectGetWidth(self.view.frame) , CGRectGetHeight(self.view.frame) )];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.tableFooterView = [[UIView alloc] init];
    
    [self.view addSubview:_tableView];
    
    _dataSource = [[NSMutableArray alloc] initWithObjects:@"开通认证",@"认证的云平台列表",@"在线充值",@"财务明细",@"发票索取",@"汇款确定",@"学习中心", nil];
}

#pragma mark -
#pragma mark --按钮的响应事件--
-(void)menu {
    NSArray * arr = nil;
    arr = @[@"退出登陆", @"基础设置",@"修改安全码"];
    _menuView = [[MenuView alloc] initWithButtonTitles:arr withDelegate:self];
    _menuView.hasImage = NO;
    [_menuView showInView:self.view origin:CGPointMake(self.view.width - 180, 70)];
    _menuView.buttonView.delegate=self;
}

#pragma mark --tableViewDelegate--
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _dataSource.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *indentifier = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:indentifier];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:indentifier];
    }
    cell.textLabel.text = _dataSource[indexPath.row];
    cell.imageView.image = [UIImage imageNamed:@"SessionBarIcon4.png"];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    
    [_dataSource enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
        
    }];
    return cell;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.frame), 0)];
    headView.backgroundColor = [UIColor colorWithRed:247/255.0 green:247/255.0 blue:247/255.0 alpha:0.9];
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 10, CGRectGetWidth(headView.frame), 20)];
    label.text = @"  官方公告:";
    label.font = [UIFont systemFontOfSize:12];
    label.backgroundColor = [UIColor lightGrayColor];
    
    UILabel *NumberLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, CGRectGetMaxY(label.frame) + 10, CGRectGetWidth(headView.frame)/2 - 15, 40)];
    NumberLabel.text = [NSString stringWithFormat:@"可用充值金额:%d元",55220];
    NumberLabel.font = [UIFont systemFontOfSize:13];
    NumberLabel.textAlignment = NSTextAlignmentCenter;
    NumberLabel.backgroundColor = [UIColor colorWithRed:237/255.00 green:236/255.00 blue:221/255.00 alpha:1.0];
    
    UILabel *YunBiLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetWidth(headView.frame)/2 + 5, CGRectGetMaxY(label.frame) + 10, CGRectGetWidth(headView.frame)/2 - 15, 40)];
    YunBiLabel.text = [NSString stringWithFormat:@"可用云代金币:%d元",12041];
    YunBiLabel.font = [UIFont systemFontOfSize:13];
    YunBiLabel.textAlignment = NSTextAlignmentCenter;
    YunBiLabel.backgroundColor = [UIColor colorWithRed:194/255.00 green:232/255.00 blue:229/255.00 alpha:1.0];
    
    headView.frame = CGRectMake(0, 0, CGRectGetWidth(self.view.frame), CGRectGetMaxY(YunBiLabel.frame) + 10);
    [headView addSubview:label];
    [headView addSubview:NumberLabel];
    [headView addSubview:YunBiLabel];
    
    
    return headView;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    UIView *headView = [self tableView:tableView viewForHeaderInSection:section];
    
    return CGRectGetHeight(headView.frame);
    
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (tableView == _tableView) {
        [tableView deselectRowAtIndexPath:indexPath animated:YES];
    }else {
        [_menuView hide];
        switch (indexPath.row) {
            case 0:
            {
               break;
            }
            case 1:
            {
                break;
            }
            case 2:
            {
                break;
            }
  
            default:
                break;
        }
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (tableView == _menuView.buttonView) {
        return 40;
    }else {
        return 50;
    }
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
